/*
 * @description: 
 * @Date: 2022-11-24 19:18:43
 * @example: 
 * @params: 
 */
import axios from "axios";
let server = axios.create({
  baseURL: "http://kai.anrookie.cn:5555",
  // baseURL:'http://localhost:7878',
  timeout: 3000,
});

//请求拦截
axios.interceptors.request.use(
  (_config) => {
    //此处可以封装一些加载状态
    const config = _config;
    console.log(config)
    const token = window.sessionStorage.getItem('token')
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截
axios.interceptors.response.use(
  response => {
    return response;
  },
  error => { 
    // 判断http状态是否是401
    if(error.response.status === 401){
      window.myVue.$router.push({path:"/"})
    }
    return Promise.reject(error);
 }
);

export default server;
